/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.csvgenerator.engine.vg;

import java.util.Random;

/**
 *
 * @author Administrator
 */
public class LinearRandomValueGenerator extends NumberValueGenerator {

    //elements
    private long lowerBound = new Long(0);
    private long upperBound = Long.MAX_VALUE;
    private float gravity = new Long(1);
    private long step = new Long(1);
    private long mod = new Long(1);
    private String prefix = "";
    private String suffix = "";
    //iterator variable holding previous value of ID
    private Long previousValue = null;
    private boolean overflow = false;

    public LinearRandomValueGenerator() {
    }

    @Override
    public String nextValue() {


        String nextValue = "";
        if (!overflow) {
            if (previousValue == null) {
                //init with lower bound
                previousValue = lowerBound;
            }
            
            nextValue = (prefix + previousValue + suffix).trim();
            previousValue += step;
            if (previousValue >= upperBound) {
                overflow = true;
                previousValue = lowerBound;
            }
        } else {
            nextValue = prefix + ((long) ((upperBound - lowerBound) * new Random().nextFloat() * gravity + lowerBound)) + suffix;
        }

        currentValue = nextValue;
        return nextValue;
    }

    /**
     * @return the lowerBound
     */
    public long getLowerBound() {
        return lowerBound;
    }

    /**
     * @param lowerBound the lowerBound to set
     */
    public void setLowerBound(long lowerBound) {
        this.lowerBound = lowerBound;
    }

    /**
     * @return the upperBound
     */
    public long getUpperBound() {
        return upperBound;
    }

    /**
     * @param upperBound the upperBound to set
     */
    public void setUpperBound(long upperBound) {
        this.upperBound = upperBound;
    }

    /**
     * @return the gravity
     */
    public float getGravity() {
        return gravity;
    }

    /**
     * @param gravity the gravity to set
     */
    public void setGravity(float gravity) {
        this.gravity = gravity;
    }

    /**
     * @return the step
     */
    public long getStep() {
        return step;
    }

    /**
     * @param step the step to set
     */
    public void setStep(long step) {
        this.step = step;
    }

    /**
     * @return the mod
     */
    public long getMod() {
        return mod;
    }

    /**
     * @param mod the mod to set
     */
    public void setMod(long mod) {
        this.mod = mod;
    }

    /**
     * @return the prefix
     */
    public String getPrefix() {
        return prefix;
    }

    /**
     * @param prefix the prefix to set
     */
    public void setPrefix(String prefix) {
        this.prefix = prefix;
    }

    /**
     * @return the suffix
     */
    public String getSuffix() {
        return suffix;
    }

    /**
     * @param suffix the suffix to set
     */
    public void setSuffix(String suffix) {
        this.suffix = suffix;
    }
}
